package com.kenny.service;

import com.kenny.service.UserService;
import com.kenny.spring.BeanPostProcessor;
import com.kenny.spring.Component;

import java.util.Objects;

@Component
public class KennyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        if (Objects.equals(beanName, "userService")) {
            System.out.println("初始化之前");
            ((UserService) bean).setName("kenny");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        System.out.println("初始化后");
        return bean;
    }
}
